package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.DisputeDetailBean;
import com.sx.zongzhi.bean.PartiesBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IDisputeAddView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *矛盾纠纷新增编辑
 */
public class DisputeAddPest {

    private IDisputeAddView iDisputeaddView;

    public DisputeAddPest(IDisputeAddView iDisputeaddView) {
        this.iDisputeaddView=iDisputeaddView;
    }


    /**
     *
     * @param url 事件地址类型
     * @param id 事件主键
     * @param bean 添加纠纷的对象
     * @param partiesBeans 主要当事人集合
     * @param files 附件
     *  @param removeId 移除
     */
    public void disputeAdd(String url, String id, DisputeDetailBean bean, List<PartiesBean> partiesBeans,
                           List<String> files, List<String> removeId){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("issue.id",id);
        map.put("issue.name",bean.getName());
        map.put("issue.occurOrg.id",bean.getOccurOrg().getId());
        map.put("issue.occurPlace",bean.getOccurPlace());
        map.put("issue.occurDate",bean.getOccurDate());
        map.put("issue.relatedUnit",bean.getRelatedUnit());
        map.put("issue.relatePeopleCount",bean.getRelatePeopleCount());
        if (partiesBeans!=null&&partiesBeans.size()>0) {
            int count = partiesBeans.size();
            for (int i = 0; i < count; i++) {
                PartiesBean partiesBean=partiesBeans.get(i);
                map.put("mainParties["+i+"].partyName",partiesBean.getPartyName());
                map.put("mainParties["+i+"].gender.id",partiesBean.getGender().getId());
                map.put("mainParties["+i+"].nation.id",partiesBean.getNation().getId());
                map.put("mainParties["+i+"].schooling",partiesBean.getSchooling());
                map.put("mainParties["+i+"].certifivateType.id",partiesBean.getCertifivateType()!=null?
                        partiesBean.getCertifivateType().getId():"");
                map.put("mainParties["+i+"].certifivateNumber",partiesBean.getCertifivateNumber());
                map.put("mainParties["+i+"].partyLinkPattern",partiesBean.getPartyLinkPattern());
                map.put("mainParties["+i+"].personnelCategory.id",partiesBean.getPersonnelCategory()!=null?
                        partiesBean.getPersonnelCategory().getId():"");
                map.put("mainParties["+i+"].partyAddress",partiesBean.getPartyAddress());
            }
        }
        map.put("issue.selectedType",bean.getIssueTypeId());
        map.put("issue.issueKind.id",bean.getIssueKind().getId());
        map.put("issue.eventSource.id",bean.getEventSource().getId());
        map.put("issue.issueContent",bean.getIssueContent());
        map.put("issue.evaluateOpinion",bean.getEvaluateOpinion());
        map.put("issue.developForecast",bean.getDevelopForecast());
        map.put("issue.adjustMeasures",bean.getAdjustMeasures());
        if (files!=null&&files.size()>0){
            for (int i=0;i<files.size();i++){
                map.put("issue.files["+i+"].path",files.get(i));
            }
        }
        if (removeId!=null&&removeId.size()>0){
            for (int i = 0 ; i < removeId.size() ; i ++){
                map.put("issue.removeIds["+i+"]",removeId.get(i));
            }
        }
        new ApiManager().addDispute(url,map, new BaseCallBack<BaseResult<DisputeDetailBean>>() {
            @Override
            public void onSuccess(BaseResult<DisputeDetailBean> response) {
                iDisputeaddView.addDispute(response.getData());
            }
            @Override
            public void onFailures(String message) {
                iDisputeaddView.showError(message);
            }
        });
    }

}
